#爬取豆瓣电影

import requests
import json

if __name__ == "__main__":
    # UA伪装
    headers = {
        'User-Agent': 'Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/105.0.0.0 Safari/537.36'
    }
    #指定URL
    url = 'https://movie.douban.com/j/chart/top_list'
    #封装字典
    param = {
        'type': '24',
        'interval_id': '100:90',
        'action':'',
        'start': '20',#从库中的第几部电源去取
        'limit': '20',#一次取出的个数
    }

    #发起请求
    response = requests.get(url=url,params=param,headers=headers)
    #获取响应数据
    list_data=response.json()#列表
    #持久化存储
    fp = open('./dianying.json','w',encoding='utf-8')
    json.dump(list_data,fp=fp,ensure_ascii=False)

    print('爬取结束！')

